<%@page contentType="text/html; charset=utf-8"%>
<%@include file="/WEB-INF/views/common/tags.jspf" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>菜单管理</title>
	<%@include file="/WEB-INF/views/common/header.jspf" %>
</head>

<body>

	<div id="dg">
		<div id="toolbars">
			<form id="searchForm">
				<div class="search-bar">
					<div class="bar-row">
						<button type="button" onclick="form_dialog('add');" class="btn btn-green btn-xs height-25 mt-3 float-left"><div class='icon-div'><i class='fa fa-plus fa-120 pt-2'></i></div> 新增</button>
						<button type="button" onclick="form_dialog('update');" class="btn btn-blue btn-xs height-25 mt-3 ml-1 float-left"><div class='icon-div'><i class='fa fa-pencil fa-120 pt-2'></i></div> 编辑</button>
						<button type="button" onclick="del();" class="btn btn-red btn-xs height-25 mt-3 ml-1 float-left"><div class='icon-div'><i class='fa fa-trash fa-120 pt-2'></i></div> 删除</button>
						<button type="button" onclick="reload();" class="btn btn-purple1 btn-xs height-25 mt-3 ml-1 float-left"><div class='icon-div'><i class='fa fa-refresh fa-120 pt-2'></i></div> 刷新</button>
						
						<shiro:hasRole name="CC">    
							<button type="button" onclick="reload();" class="btn btn-purple1 btn-xs height-25 mt-3 ml-1 float-left"><div class='icon-div'><i class='fa fa-refresh fa-120 pt-2'></i></div> 测试授权</button>
						</shiro:hasRole>
						
						<div class="bar-input ml-10">
		            		<input name="quickSearch" class="easyui-searchbox" data-options="searcher:quickSearch, width: 150, height: 25,prompt: '快速搜索...'" />
	            		</div>
					</div>
				</div>
			</form>
		</div>
	</div>
	
	
	<%@include file="/WEB-INF/views/common/script.jspf" %>
	<script>
	var $dg ;
	$(function(){
		$dg = $("#dg").datagrid({
			title: "菜单管理",
            url: "${ctx}/admin/sys/menu/datagrid",
            idField: "id", fit: true, 
            border: false, striped:true, pageSize: 30, pageList: [30,40,50,100,200,500,1000], 
            pagination: true, rownumbers: true, toolbar: "#toolbars", remoteSort: true, 
            sortName: 'createTime', sortOrder: 'desc',
            frozenColumns: [[
                { field: "ck", checkbox: true },
                { field: "id", title: "ID", width: 80, sortable: true }
            ]],
            columns: [[
                { field: "name", title: "名称", width: 180, formatter: function(val, row){
                	return "<span class=\"fa fa-"+(row.icon?row.icon:"viacoin")+" fa-120 ml-5 mt-5\"></span>　"+val;
                } },
                { field: "selected", title: "默认显示", width: 150, align: "center", formatter: function(val, row){
                	return (val?"<span style='color:red'>是</span>":"否");
                } },
                { field: "showStyle", title: "展示样式", width: 150, align: "center", formatter: function(val, row){
                	return (val?"树状菜单":"手风琴");
                } },
                { field: "createTime", title: "创建时间", width: 150, sortable: true }
            ]],
            onLoadSuccess: function(){
            	$.fn.datagrid.extensions.onLoadSuccess.apply(this, arguments);
            	$dg.datagrid('unselectAll');$dg.datagrid('clearSelections');
            },
            enableHeaderClickMenu: true, enableHeaderContextMenu: true, enableRowContextMenu: false
        });
	});
	function reload(){$dg.datagrid("reload") ;}
	function quickSearch(value,name){
		var o = {} ; o[name] = value ; $dg.datagrid("load",o);
	}
	function getIds() {
		var rows = $dg.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				if(undefined != rows[i].id && ""!=rows[i].id) {
					ids.push(rows[i].id);
				}
			}
		}
		return ids ;
	}	
	
	function form_dialog(formType) {
		var form_url = "${ctx}/admin/sys/menu/form";
		if(formType === "update") {
			var ids = getIds() ;
			if(ids.length == 0) {alertify.warning("请选择一条记录！");return;}
			if(ids.length > 1) {alertify.warning("只能编辑一条记录！");return;}
			form_url = "${ctx}/admin/sys/menu/form?id="+ids[0];
		}
		
		var $d = $.easyui.showDialog({
			href: form_url, title: '<div class="icon-div"><i class="fa fa-link fa-120 pt-2 fa-c-blue"></i></div> 表单', iniframe: false, topMost: true, iconCls : '',
			width: 450, height: 225, maximizable: true,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '<i class="fa fa-save fa-120 mt-6 fa-c-green"></i> 应用', handler : function() { $.easyui.parent.submitForm($d, $dg, true) ; } },
              { text : '<i class="fa fa-save fa-120 mt-6 fa-c-blue"></i> 保存', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '<i class="fa fa-remove fa-120 mt-6 fa-c-red"></i> 关闭', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	
	function del() {
		if(getIds().length == 0) {alertify.warning("请选择一条记录！");return;}
		$.messager.confirm("您确定要进行该操作？", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "数据删除中，请稍等..."});
				deletedAjax("${ctx}/admin/sys/menu/delete", {"ids" : getIds().join(',')}) ;
			}
		});
	}
	function deletedAjax(url, params) {
		$.post(url, params, function(result) {
			if (result.status) {
				$dg.datagrid("unselectAll");$dg.datagrid("reload") ;
				alertify.success(result.message);
				$.easyui.loaded();
			} else {
				alertify.warning(result.message);
				$.easyui.loaded();
			}
		}, 'json').error(function() { $.easyui.loaded(); });
	}
	</script>
</body>
</html>

